package Test_1110;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
public class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int len=m+n-1;
        int last1=m-1;
        int last2=n-1;
        while(last1>=0 && last2>=0){
        if(nums1[last1]<nums2[last2]){
            nums1[len--]=nums2[last2--];
        }else{
            nums1[len--]=nums1[last1--];
        }
    }
        while(last2>=0){
            nums1[len--]=nums2[last2--];
        }
    }
    //删除排序数组中的重复项
    public int removeDuplicates(int[] nums) {
        int len=nums.length;
        int j=0;
        if(len==0){
            return len;
        }
        for (int i = 0; i < len; i++) {
            if(i==0 || (nums[i]!=nums[i-1])){
                nums[j]=nums[i];
                j++;
            }
        }
        return j;
    }
    //原地移除数组中所有的元素va
    public int removeElement(int[] nums, int val) {
        int len=nums.length;
        int[] n=new int[len];
        int j=0;
        for (int i = 0; i < len;) {
            if((nums[i]^val)==0 ){
                i++;
            } else{
                n[j]=nums[i];
                j++;
                i++;
            }

        }
        for (int i = 0; i < len; i++) {
            nums[i]=0;
        }
        for (int i = 0; i < j; i++) {
            nums[i]=n[i];
        }
        return j;
    }
}
